package stu.day25_day32.day30;

import java.util.Scanner;

public class hw1 {
    public static boolean flag;



    public static void backtrack(char[][] ch1,int[][] arrays,int i,int j,int num,String str){
        if(num==str.length()){
            flag = true;
            return;
        }
        int n = ch1.length;
        int m = ch1[0].length;

        if( i>=0 && i<n && j>=0 && j<m) {
            if (ch1[i][j] == str.charAt(num) && arrays[i][j] == 0) {
                arrays[i][j] = 1;
                backtrack(ch1, arrays, i - 1, j, num + 1, str);
                backtrack(ch1, arrays, i + 1, j, num + 1, str);
                backtrack(ch1, arrays, i, j - 1, num + 1, str);
                backtrack(ch1, arrays, i, j + 1, num + 1, str);
                arrays[i][j] = 0;

            }
        }


    }



    public static void main(String[] args) {
        // 数据输入
        Scanner sc = new Scanner(System.in);
        String[] s1 =sc.nextLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int m = Integer.parseInt(s1[1]);

        String str = sc.nextLine();

        char[][] ch1 = new char[n][m];
        for(int i=0;i<n;i++){
            String s2 =sc.nextLine();
            for(int j=0;j<m;j++){
                ch1[i][j] = s2.charAt(j);
            }
        }

        // 数据
        int[][] arrays = new int[n][m];


        // 回溯
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(ch1[i][j]==str.charAt(0)){
                    backtrack(ch1,arrays,i,j,0,str);
                    if(flag){
                        i++;
                        j++;
                        System.out.println(i+" "+j);
                        break;
                    }

                }
            }
        }


        if(!flag){
            System.out.println("NO");
        }




    }






}
